import 'entity_factory.dart';

///解析List<T> 类型的数据
class BaseListEntity<T> {
  int code;
  String msg;
  List<T> data;

  bool get isSuccess{
    return code==0;
  }

  BaseListEntity({required this.code, required this.msg, required this.data});

  factory BaseListEntity.fromJson(json) {
    if (json == null || json.isEmpty) {
      return BaseListEntity(code: -1, msg: '无响应数据', data: []);
    }
    return BaseListEntity(
        code: json['code'] ?? -1,
        msg: json['msg'] ?? '无响应数据',
        data: json['data'] == null
            ? List.empty()
            : (json['data'] as List).map((e) {
                if (T.toString() == 'String') {
                  return e as T;
                } else {
                  return EntityFactory.convertOBJ<T>(e)!;
                }
              }).toList());
  }
}
